#!/usr/bin/python
import sys
import math
def binary_search(A, v, p, r):
	'''Searches A for v starting at index p and ending at index r.'''
	if p < r:
		midpoint = int(math.floor((p + r) / 2))
		if v <= midpoint:
			return binary_search(A, v, p, midpoint)
		else:
			return binary_search(A, v, midpoint + 1, r)
	return r, p

if __name__ == '__main__':
	A = [1, 2, 3, 4, 5]
	print binary_search(A, 5, 0, len(A) - 1) 
